package main

import (
	"fmt"
	"sync"
	"time"
)

var mutex sync.Mutex //创建一个互斥锁，新建互斥锁的状态为0,表示未加锁.

func printer(str string) {
	mutex.Lock() //访问共享数据前加锁
	for _, ch := range str {

		fmt.Printf("%c", ch)
		time.Sleep(time.Millisecond * 300)
	}
	mutex.Unlock() //共享数据访问结束后解锁
}

func person1() {
	printer("hello")

}

func person2() {

	printer("world")
}

func main() {
	person1()
	person2()

}
